﻿using Coway.Ordering.Products;
using Coway.Ordering.Sellers;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Guids;

namespace Coway.Ordering
{
    public class OrderingDataSeederContributor : IDataSeedContributor, ITransientDependency
    {
        private readonly IRepository<Product, Guid> _productRepository;
        private readonly IRepository<Seller, string> _sellerRepository;
        private readonly IGuidGenerator _guidGenerator;

        public OrderingDataSeederContributor(
            IRepository<Product, Guid> productRepository,
            IRepository<Seller, string> sellerRepository,
            IGuidGenerator guidGenerator)
        {
            _productRepository = productRepository;
            _sellerRepository = sellerRepository;
            _guidGenerator = guidGenerator;
        }

        public async Task SeedAsync(DataSeedContext context)
        {
            await SeedProductsAsync();
            await SeedSellersAsync();
        }

        private async Task SeedProductsAsync()
        {
            if (await _productRepository.GetCountAsync() > 0)
            {
                return;
            }

            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 1,
                    model: "CHP-671L",
                    dispalyName: "STANDING WATER PURIFIER",
                    dispalyNameCN: "立式净水器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 2,
                    model: "CHP-590L",
                    dispalyName: "STANDING WATER PURIFIER",
                    dispalyNameCN: "立式净水器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 3,
                    model: "CHPI-620L",
                    dispalyName: "STANDING WATER PURIFIER",
                    dispalyNameCN: "立式净水器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 4,
                    model: "CHPI-280L",
                    dispalyName: "COUNTERTOP ICE WATER PURIFIER",
                    dispalyNameCN: "台式净水器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 5,
                    model: "CHP-251L",
                    dispalyName: "COUNTERTOP ICE WATER PURIFIER",
                    dispalyNameCN: "台式净水器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 6,
                    model: "CP-251L",
                    dispalyName: "COUNTERTOP ICE WATER PURIFIER",
                    dispalyNameCN: "台式净水器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 7,
                    model: "P-07QL",
                    dispalyName: "COUNTERTOP ICE WATER PURIFIER",
                    dispalyNameCN: "台式净水器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 8,
                    model: "P-09CL",
                    dispalyName: "UNDER SINK WATER PURIFIER",
                    dispalyNameCN: "厨下净水器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 9,
                    model: "AP-3018B",
                    dispalyName: "SUPER CAPACITY AIR PURIFIER",
                    dispalyNameCN: "大面积空气净化器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 10,
                    model: "AP-1516D",
                    dispalyName: "MULTIACTION AIR PURIFIER",
                    dispalyNameCN: "多功能空气净化器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 11,
                    model: "AP-1018F",
                    dispalyName: "SLIM AIR PURIFIER",
                    dispalyNameCN: "超薄型空气净化器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 12,
                    model: "AP-1511FHE",
                    dispalyName: "PLASMA FILTER AIR PURIFIER",
                    dispalyNameCN: "RBD等离子体空气净化器"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 13,
                    model: "BAS-22",
                    dispalyName: "SELF-CLEANING BIDET",
                    dispalyNameCN: "智能清洁便座"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 14,
                    model: "BA-13",
                    dispalyName: "INSTANT WATER HEATING BIDET",
                    dispalyNameCN: "即热型智能便座"
                )
            );
            await _productRepository.InsertAsync(
                new Product(
                    id: _guidGenerator.Create(),
                    no: 15,
                    model: "BB-14BUS",
                    dispalyName: "ULTRA SLIM WATER SOFTENER",
                    dispalyNameCN: "超小型软水机"
                )
            );
        }
        private async Task SeedSellersAsync()
        {
            if (await _sellerRepository.GetCountAsync() > 0)
            {
                return;
            }

            await _sellerRepository.InsertAsync(
                new Seller(
                    id: _guidGenerator.Create().ToString(),
                    code: "108804",
                    name: "fanming meng",
                    phone: "6268618880",
                    email: "mfm84818@gmail.com",
                    managerEmail: "mfm84818@gmail.com"
                )
            );

            await _sellerRepository.InsertAsync(
                new Seller(
                    id: _guidGenerator.Create().ToString(),
                    code: "108910",
                    name: "stephanie fung",
                    phone: "6262534505",
                    email: "stepfung3833@gmail.com",
                    managerEmail: "mfm84818@gmail.com"
                )
            );

            await _sellerRepository.InsertAsync(
                new Seller(
                    id: _guidGenerator.Create().ToString(),
                    code: "108899",
                    name: "ding ji zhuang",
                    phone: "6268185658",
                    email: "canaaneducationusa@gmail.com",
                    managerEmail: "mfm84818@gmail.com"
                )
            );

        }
    }
}
